using NUnit.Framework;
using UseCaseManager.BO;

namespace UseCaseManager.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for Drop objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for Drop.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDrop
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.TestFixtureSetup();
        }

        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            Drop drop = TestUtilsDrop.CreateUnsavedValidDrop();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string actualToString = drop.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(drop.Name, actualToString);
        }

        [Test]
        public void Test_ToString_NameNullString()
        {
            //---------------Set up test pack-------------------
            Drop drop = TestUtilsDrop.CreateUnsavedValidDrop();
            drop.Name = "";
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string actualToString = drop.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(drop.EndDate.ToString(), actualToString);
        }

        [Test]
        public void Test_NewUseCasesAddedToDrop()
        {
            //---------------Set up test pack-------------------
            Drop drop = TestUtilsDrop.CreateUnsavedValidDrop();
            drop.UseCases.Add(TestUtilsUseCase.CreateUnsavedValidUseCase());
            drop.UseCases.Add(TestUtilsUseCase.CreateUnsavedValidUseCase());
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, drop.UseCases.Count);
            Assert.AreEqual(2, drop.UseCases.CreatedBusinessObjects.Count);
            Assert.AreEqual(0, drop.UseCases.AddedBusinessObjects.Count);
            //---------------Execute Test ----------------------
            drop.Save();
            drop.UseCases.Clear();
            //---------------Test Result -----------------------
            Assert.AreEqual(2, drop.UseCases.Count);
            Assert.AreEqual(0, drop.UseCases.AddedBusinessObjects.Count);
            Assert.AreEqual(0, drop.UseCases.CreatedBusinessObjects.Count);
        }

        [Test]
        public void Test_SavedUseCasesAddedToDrop()
        {
            //---------------Set up test pack-------------------
            Drop drop = TestUtilsDrop.CreateUnsavedValidDrop();
            drop.UseCases.Add(TestUtilsUseCase.CreateSavedUseCase());
            drop.UseCases.Add(TestUtilsUseCase.CreateSavedUseCase());
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, drop.UseCases.Count);
            Assert.AreEqual(0, drop.UseCases.CreatedBusinessObjects.Count);
            Assert.AreEqual(2, drop.UseCases.AddedBusinessObjects.Count);
            //---------------Execute Test ----------------------
            drop.Save();
            drop.UseCases.Clear();
            //---------------Test Result -----------------------
            Assert.AreEqual(2, drop.UseCases.Count);
            TestUtilsDrop.AssertUseCasesNotDirty(drop.UseCases);
            Assert.AreEqual(0, drop.UseCases.AddedBusinessObjects.Count);
            Assert.AreEqual(0, drop.UseCases.CreatedBusinessObjects.Count);
        }

        [Test]
        public void Test_Calculate_PointsAssigned()
        {
            //---------------Set up test pack-------------------
            int expectedTotalPoints;
            const int expectedNumberOfUseCases = 3;
            Drop drop = TestUtilsDrop.CreateSavedDrop_WUseCases(expectedNumberOfUseCases, out expectedTotalPoints);
            //---------------Assert Precondition----------------
            Assert.AreEqual(expectedNumberOfUseCases, drop.UseCases.Count);
            //---------------Execute Test ----------------------
            int totalPoints = drop.PointsAssigned.Value;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedTotalPoints, totalPoints);
        }

        [Test]
        public void Test_Calculate_PointsBaseline()
        {
            //---------------Set up test pack-------------------
            int expectedTotalPointsAssigned;
            const int expectedNumberOfUseCases = 3;
            Drop drop = TestUtilsDrop.CreateSavedDrop_WUseCases(expectedNumberOfUseCases, out expectedTotalPointsAssigned);
            int expectedBaselineTotalPoints = expectedTotalPointsAssigned;
            //---------------Assert Precondition----------------
            Assert.AreEqual(expectedNumberOfUseCases, drop.UseCases.Count);
            Assert.AreEqual(expectedTotalPointsAssigned, drop.PointsAssigned);
            //---------------Execute Test ----------------------
            drop.SetBaseline();
            int totalBaselinePoints = drop.PointsBaseline.GetValueOrDefault();
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedBaselineTotalPoints, totalBaselinePoints);
        }

        [Test]
        public void Test_Calculate_PointsCompleted()
        {
            //---------------Set up test pack-------------------
            int expectedTotalPointsAssigned;
            const int expectedNumberOfUseCases = 3;
            Drop drop = TestUtilsDrop.CreateSavedDrop_WUseCases(expectedNumberOfUseCases, out expectedTotalPointsAssigned);
            int expectedTotalPointsCompleted = expectedTotalPointsAssigned;
            foreach (UseCase useCase in drop.UseCases)
            {
                useCase.CompletedInDropID = drop.DropID;
            }
            //---------------Assert Precondition----------------
            Assert.AreEqual(expectedNumberOfUseCases, drop.UseCases.Count);
            Assert.AreEqual(expectedTotalPointsAssigned, drop.PointsAssigned);
            //---------------Execute Test ----------------------
            int totalCompletedPoints = drop.PointsCompleted.GetValueOrDefault();
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedTotalPointsCompleted, totalCompletedPoints);
        }
        [Test]
        public void Test_Calculate_PointsCompleted_SomeIncomplete()
        {
            //---------------Set up test pack-------------------
            int expectedTotalPointsAssigned;
            const int expectedNumberOfUseCases = 3;
            Drop drop = TestUtilsDrop.CreateSavedDrop_WUseCases(expectedNumberOfUseCases, out expectedTotalPointsAssigned);
            drop.UseCases[0].CompletedInDropID = drop.DropID;
            drop.UseCases[1].CompletedInDropID = null;
            drop.UseCases[2].CompletedInDropID = drop.DropID;
            int expectedTotalPointsCompleted = expectedTotalPointsAssigned - drop.UseCases[1].PointsAssigned.Value;
            //---------------Assert Precondition----------------
            Assert.AreEqual(expectedNumberOfUseCases, drop.UseCases.Count);
            Assert.AreEqual(expectedTotalPointsAssigned, drop.PointsAssigned);
            //---------------Execute Test ----------------------
            int totalCompletedPoints = drop.PointsCompleted.GetValueOrDefault();
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedTotalPointsCompleted, totalCompletedPoints);
        }

        [Test]
        public void Test_SetCumulativeAssignedPointsRemaining()
        {
            //---------------Set up test pack-------------------
            Drop drop = TestUtilsDrop.CreateUnsavedDefaultDrop();
            int expectedCumulativePoints = TestUtils.GetRandomInt(0, 50);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            drop.CumulativePointsAssignedRemaining = expectedCumulativePoints;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedCumulativePoints, drop.CumulativePointsAssignedRemaining);
        }
    }
}